package com.smh;

import java.util.ArrayDeque;
import java.util.Stack;

/**
 * @author shiminghui
 * @date 2025/2/17 9:31
 * @description: TODO
 */
public class _019_双栈实现队列 {
    private class MyQueue {

        private final ArrayDeque<Integer> stack1 = new ArrayDeque<>();
        private final ArrayDeque<Integer> stack2 = new ArrayDeque<>();

        public MyQueue() {

        }

        public void push(int x) {
            stack1.push(x);
        }

        public int pop() {
            while (!stack1.isEmpty()) {
                stack2.push(stack1.pop());
            }
            int res = stack2.pop();
            while (!stack2.isEmpty()) {
                stack1.push(stack2.pop());
            }
            return res;
        }

        public int peek() {
            while (!stack1.isEmpty()) {
                stack2.push(stack1.pop());
            }
            int res = stack2.peek();
            while (!stack2.isEmpty()) {
                stack1.push(stack2.pop());
            }
            return res;
        }

        public boolean empty() {
            return stack1.isEmpty();
        }
    }
}
